// 引入路由组件
// import Home from "@/pages/Home";
// import Search from "@/pages/Search";
// import Login from "@/pages/Login";
// import Register from "@/pages/Register";
// import Detail from "@/pages/Detail";
// import AddCartSuccess from "@/pages/AddCartSuccess";
// import ShopCart from "@/pages/ShopCart";
// import Trade from "@/pages/Trade";
// import Pay from "@/pages/Pay";
// import PaySuccess from "@/pages/PaySuccess";
// import Center from "@/pages/Center";

//引入二级路由组件
import MyOrder from "@/pages/Center/myOrder";
import GroupOrder from "@/pages/Center/groupOrder";

//路由懒加载--高效

//路由配置的信息
export default [
    {
        path: "/center",
        component: ()=>import("@/pages/Center"),
        meta: { show: true },
        //子路由（二级路由）
        children:[
            {
                path: 'myorder',
                component: MyOrder
            },
            {
                path: 'grouporder',
                component: GroupOrder
            },
            //重定向
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ]
    },
    {
        path: "/paysuccess",
        component: ()=>import("@/pages/PaySuccess"),
        meta: { show: true }
    },
    {
        path: "/pay",
        component: ()=>import("@/pages/Pay"),
        meta: { show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            // ...
            // console.log('路由独享守卫');
            if(from.path=='/trade'){
                next()
            }else{
                //next(false)：从哪来回哪儿去。中断当前的路由
                next(false)
            }
        }
    },
    {
        path: "/trade",
        component: ()=>import("@/pages/Trade"),
        meta: { show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            // console.log('路由独享守卫');
            //去交易页面，必须是从购物车而来
            if(from.path=='/shopcart'){
                next()
            }else{
                //从其他页面跳去trade交易页面 ，不行，只能从shopcart购物车页面跳去交易页面
                //next(false)：从哪来回哪儿去。中断当前的路由
                //其他的路由组件而来，停留在当前
                next(false)
            }
        }
    },
    {
        path: "/shopcart",
        component: ()=>import("@/pages/ShopCart"),
        meta: { show: true }
    },
    {
        path: "/addCartSuccess",
        name: 'addCartSuccess',
        // component: AddCartSuccess,
        component: ()=>import("@/pages/AddCartSuccess"),
        meta: { show: true }
    },
    {
        path: "/detail/:skuid",
        component: ()=>import("@/pages/Detail"),
        meta: { show: true }
    },
    {
        path: "/home",
        // component: Home,
        component: ()=>import("@/pages/Home"),
        meta: { show: true }
    },
    {
        path: "/search/:keyword?",
        component: ()=>import("@/pages/Search"),
        meta: { show: true },
        name: "search",
        // 路由组件能不能传递prop数据
        // 1. 布尔值写法 只有params参数
        // props:true,
        // 2. 对象写法
        // props:{a:1, b:2}
        // 3.函数写法：可以把params参数、query参数，通过props传递给路由组件
        props: ($route) => {
            return { keyword: $route.params.keyword, k: $route.query.K }
        }

    },
    {
        path: "/login",
        component: ()=>import("@/pages/Login"),
        meta: { show: false }
    },
    {
        path: "/register",
        component: ()=>import("@/pages/Register"),
        meta: { show: false }
    },
    // 重定向， 在项目跑起来的时候，访问/立马让它定向到首页
    {
        path: '/',
        redirect: '/home'
    }
]